package com.fjp.heartguard.app.network

import com.fjp.heartguard.app.data.bean.AccountState
import com.fjp.heartguard.app.data.bean.AppVersion
import com.fjp.heartguard.app.data.bean.Message
import com.fjp.heartguard.app.data.bean.OlderInfo
import com.fjp.heartguard.app.data.bean.OlderList
import com.fjp.heartguard.app.data.bean.OverdueOlder
import com.fjp.heartguard.app.data.bean.QuestionnatireCount
import com.fjp.heartguard.app.data.bean.Reports
import com.fjp.heartguard.app.data.bean.ReportsDetail
import com.fjp.heartguard.app.data.bean.ReportsHistory
import com.fjp.heartguard.app.data.bean.SaveQuestionResult
import com.fjp.heartguard.app.data.bean.UpdateImageResult
import com.fjp.heartguard.app.data.bean.UserInfo
import okhttp3.MultipartBody

/**
 *
 * 时间　: 2020/5/4
 * 描述　: 处理协程的请求类
 */

val HttpRequestCoroutine: HttpRequestManger by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
    HttpRequestManger()
}

class HttpRequestManger {

    /**
     * 注册并登陆
     */
    suspend fun login(mobile: String, password: String): ApiResponse<UserInfo> {
        return apiService.login(mobile, password)
    }

     /**
     * 获取验证码
     */
    suspend fun getCode(mobile: String): ApiResponse<String> {
        return apiService.getCode(mobile)
    }

     /**
     * 检验证码
     */
    suspend fun checkCode(mobile: String,code:String): ApiResponse<String> {
        return apiService.checkCode(mobile,code)
    }


    /**
     * 获取用户信息
     */
    suspend fun getUserInfo(): ApiResponse<UserInfo> {
        return apiService.getUserInfo()
    }

    /**
     * 版本检测
     */
    suspend fun checkVersion(): ApiResponse<AppVersion> {
        return apiService.checkVersion()
    }

    /**
     * 我的-测评数据统计
     */
    suspend fun getQuestionnaireCount(): ApiResponse<QuestionnatireCount> {
        return apiService.getQuestionnaireCount()
    }

    /**
     * 获取首页状态
     */
    suspend fun getState(version: String): ApiResponse<AccountState> {
        return apiService.getState(version)
    }

    /**
     *所有预期老人
     */
    suspend fun getOverdueOlders(): ApiResponse<Array<OverdueOlder>> {
        return apiService.getOverdueOlders()
    }

    /**
     *消息未读数量
     */
    suspend fun unreadNumbers(): ApiResponse<Int> {
        return apiService.unreadNumbers()
    }


    /**
     *消息列表
     */
    suspend fun getMessageList(): ApiResponse<ArrayList<Message>> {
        return apiService.getMessageList()
    }

    /**
     *消息详情
     */
    suspend fun getMessageDetail(id: Int): ApiResponse<Message> {
        return apiService.getMessageDetail(id)
    }

    /**
     *问卷评估列表
     */
    suspend fun getQuestionnaireList(keyword: String, page: Int, pageSize: Int, dataType: Int,olderId:Int): ApiResponse<Reports> {
        return apiService.getQuestionnaireList(keyword, page, pageSize, dataType,olderId)
    }
 /**
     *老人列表
     */
    suspend fun getOlderList(keyword: String, page: Int, pageSize: Int, dataType: Int): ApiResponse<OlderList> {
        return apiService.getOlderList(keyword, page, pageSize, dataType)
    }

    /**
     *老人测评历史
     */
    suspend fun getolderAllQuestionnaire(olderId: Int, dataType: Int): ApiResponse<ArrayList<ReportsHistory>> {
        return apiService.getOlderAllQuestionnaire(olderId, dataType, 1, 10000)
    }

    /**
     *问卷详情
     */
    suspend fun getQuestionnaireInfo(id: Int): ApiResponse<ReportsDetail> {
        return apiService.getQuestionnaireInfo(id)
    }

    /**
     *保存调查人员信息
     */
    suspend fun saveInfo(userInfo: UserInfo): ApiResponse<String> {
        return apiService.saveInfo(userInfo)
    }

    /**
     *保存老年人健康追踪评估问卷
     */
    suspend fun saveQuestionnaireInfo(olderInfo: OlderInfo): ApiResponse<SaveQuestionResult> {
        return apiService.saveQuestionnaireInfo(olderInfo)
    }

    suspend fun uploadImg(body: MultipartBody.Part): UpdateImageResult {
        return apiService.uploadImg(body)
    }

    suspend fun deviceAdd(version: String,no:String,province:String,city:String,district:String): ApiResponse<String>  {
        return apiService.deviceAdd(version,no,province,city,district,"1")
    }
}